package com.chengjue.movie;

import com.chengjue.dao.RequireModelMapper;
import com.chengjue.model.RequireModel;
import com.chengjue.utils.URLFecter;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class GetMovieRunnable implements Runnable {


    private RequireModelMapper requireModelMapper;

    Logger logger = LoggerFactory.getLogger(GetMovieRunnable.class);

     private Long id;


    public GetMovieRunnable(RequireModelMapper requireModelMapper, Long id) {
        this.requireModelMapper = requireModelMapper;
        this.id = id;
    }

    @Override
    public void run() {
        HttpClient client = new DefaultHttpClient();
        String url ="http://www.hengdiantour.com/guestbook.asp?page=";
        for(int i = 1;i<=25; i++){
            try {
                List<RequireModel> data = URLFecter.parseMovie(client, url+i);
                logger.error("user id "+id);
                logger.error(data.size()+"size");
                for(RequireModel item:data){
                    item.setUserId(id);
                    logger.error(item.toString());
                    requireModelMapper.insert(item);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
